package com.kefu.call.vo;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.common.context.KefuContext;
import com.kefu.common.vo.AbstractSearchVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;


@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel(description = "呼叫留言")
public class CallVoiceMailSearchVo extends AbstractSearchVo {

	@ApiModelProperty(value = "创建时间开始")
	private Long createTimeStart;
	@ApiModelProperty(value = "创建时间结束")
	private Long createTimeEnd;
    @ApiModelProperty(value = "留言状态 0=未处理，1=已处理")
    private Integer msgState;
    @ApiModelProperty(value = "留言类型 0=无效留言，1=有效留言")
    private Integer msgType;
    @ApiModelProperty(value = "客户电话")
    private String customerPhone;



    public <T>QueryWrapper<T> builder(){
    	QueryWrapper<T> wrapper=Wrappers.query();
		if (msgState != null) {
		    wrapper.eq("msg_state", msgState);
		}
		if (msgType != null) {
		    wrapper.eq("msg_type", msgType);
		}
	    if (StringUtils.isNotBlank(customerPhone)) {
	        wrapper.like("customer_phone",customerPhone);
	    }
		if (createTimeStart != null) {
		    wrapper.ge("createTime", Timestamp.valueOf(DateUtil.date(createTimeStart).toString()));
		}
		if (createTimeEnd != null) {
		    wrapper.le("createTime", Timestamp.valueOf(DateUtil.date(createTimeEnd).toString()));
		}
	    wrapper.eq("tenant_id", KefuContext.getKefuContext().getTenantId());
		wrapper.orderByDesc("createTime");
	    return wrapper;
	}
}